
import {Configuration} from "./Configuration";
import {GenerateTarget} from "./GenerateTarget";

export class Builder{
    configuration: Configuration;
    generateTargets: GenerateTarget[];
    rootPath: string;
    constructor(config, rootPath){
        this.configuration = new Configuration(config);
        this.generateTargets = [];
        this.rootPath = rootPath;
    }

    loadGenerateTarget(entitys){
        if(!entitys || entitys.length === 0) return entitys;
        entitys = this.configuration.strategy.generateTable.getRemainEntities(entitys);
        for(let target of this.configuration.targets){
            if(!target.enable) continue;
            target.overridable = target.overridable || this.configuration.strategy.fileOverridable;
            if(target.statically){
                this.generateTargets.push(new GenerateTarget(this.configuration, target, null, this.rootPath));
                continue;
            }
            for(let entity of entitys){
                this.generateTargets.push(new GenerateTarget(this.configuration, target, entity, this.rootPath));
            }
        }
    }
}
